#pragma once

#include <string>
#include "leveldb/status.h"
#include "leveldb/slice.h"
#include "db/memtable.h"
#include "db/dbformat.h"

namespace leveldb {
	struct Options;
	class WriteBatch;
}//namespace leveldb

class Topic {
public:
	Topic(const std::string & name, const leveldb::Options & options);
	virtual ~Topic();

	leveldb::Status close();
	leveldb::Status open();

	leveldb::Status put(const leveldb::Slice & key, const leveldb::Slice & value);
	leveldb::Status get(const leveldb::Slice & key, std::string & value);
	leveldb::Status del(const leveldb::Slice & key);

private:
	leveldb::Status write(leveldb::WriteBatch* updates);
	uint64_t getLastSequence() const{
		return last_sequence_;
	}
	void setLastSequence(uint64_t last_sequence){
		last_sequence_ = last_sequence;
	}
private:
	std::string _name;
	leveldb::InternalKeyComparator internal_comparator_;
	leveldb::MemTable* mem_ = nullptr;
	leveldb::MemTable* imm_ = nullptr;
	uint64_t last_sequence_ = 0;
};
